import dayjs from 'dayjs'

// 发布时间
export const toDate = dateValue => {
  if (!dateValue) {
    return ''
  }

  let date = dayjs(dateValue)
  let now = dayjs()

  if (!date.isValid()) {
    return ''
  }

  let second = now.diff(date, 'second')
  let minute = now.diff(date, 'minute')
  let hour = now.diff(date, 'hour')
  let day = now.diff(date, 'day')
  /* let month = now.diff(date, 'month')
  let year = now.diff(date, 'year')

  let Year = date.format('YYYY') */
  let ny = now.format('YYYY')
  let oy = date.format('YYYY')
  let Moth = date.format('MM')
  let Day = date.format('DD')
  let Hour = date.format('hh')
  let Minute = date.format('mm')

  if (oy < ny) {
    let y = date.format('YY')
    return `${y}-${Moth}-${Day}`
  } else if (day > 0) {
    return `${Moth}-${Day} ${Hour}:${Minute}`
  } else if (hour > 0) {
    return `${hour}小时前`
  } else if (minute > 0) {
    return `${minute}分钟前`
  } else if (second > 0) {
    return `${second}秒前`
  } else {
    return '刚刚'
  }
}

// 数据转换
export const numValue = num => {
  let n = ''
  if (num >= 11000 && num <= 1000000) {
    n = Math.floor(num / 1000) / 10
    return `${n}万`
  } else if (num >= 1000000) {
    n = Math.floor(num / 1000) / 10
    return `${n}万`
  } else {
    return num
  }
}

export const verifiedType = user => {
  if (user.verified) {
    if (user.verified_type === 2 || user.verified_type === 3) {
      return 'm-icon-bluev'
    } else if (user.verified_type === 0 && user.verified_type_ext === 1) {
      return 'm-icon-goldv'
    } else if (user.verified_type === 0 && user.verified_type_ext === 0) {
      return 'm-icon-yellowv'
    }else if (user.verified_type === 0 && user.verified_type_ext === 2) {
      return 'm-icon-orangev'
    }
  } else {
    if (user.verified_type === 220) {
      return 'm-icon-club'
    }
  }
}
